from goods.models import GoodsCategory


def breadcrumb(category):
    # 面包屑导航
    breadcrumb = dict(
        category_1='',
        category_2='',
        category_3=''
    )

    # 传入的是一级菜单
    if category.parent is None:
        parent_subs = category
        breadcrumb["category_1"] = parent_subs
    # 三级级菜单
    elif category.subs.count() == 0:
        goods_cat = category
        breadcrumb["category_3"] = goods_cat
        goods_parents = category.parent
        breadcrumb["category_2"] = goods_parents
        parent_subs = category.parent.parent
        breadcrumb["category_1"] = parent_subs
    # 二级
    else:
        goods_cat = category.parent
        breadcrumb["category_1"] = goods_cat
        goods_parents = category
        breadcrumb["category_2"] = goods_parents

    return breadcrumb
